import React, { Component } from 'react'
import LoginModal from '@COMPONENTS/Login/LoginModal'
import { getPlatform } from '@UTILS/common'

export default function withWebLogin(WrappedPage) {
  const { isWeb } = getPlatform()
  class WrappedComponent extends Component {
    state = {
      showLoginModal: false,
    }

    onCloseModal = () => {
      this.setState({
        showLoginModal: false,
      })
    }

    showLogin = () => {
      this.setState({
        showLoginModal: true,
      })
    }

    render() {
      const { showLoginModal } = this.state
      const { onLoginSuccess } = this.props
      return (
        <>
          <WrappedPage {...this.props} showLogin={this.showLogin} />
          <LoginModal showModal={showLoginModal} onCloseModal={this.onCloseModal} onLoginSuccess={onLoginSuccess} />
        </>
      )
    }
  }
  return isWeb ? WrappedComponent : WrappedPage
}
